<?php
/**
 * Created by PhpStorm.
 * User: 44766
 * Date: 2018-12-02
 * Time: 20:36
 */

namespace App\Http\Controllers;


use EasyWeChat\Factory;

class HomeController
{
    public function index()
    {
        $config = [
            // ...
            'oauth' => [
                'scopes'   => ['snsapi_userinfo'],
                'callback' => '/oauth_callback',
            ],
            // ..
        ];

        $app = Factory::officialAccount($config);
        $oauth = $app->oauth;
        // 未登录
        if (empty($_SESSION['wechat_user'])) {

            $_SESSION['target_url'] = '/';

            return $oauth->redirect();
            // 这里不一定是return，如果你的框架action不是返回内容的话你就得使用
            // $oauth->redirect()->send();
        }

        // 已经登录过
        $user = $_SESSION['wechat_user'];
        dd($user);
    }
}